<?php 
require_once("Util.php");
require_once("Config.php");
require_once("MsgStack.php");
session_start();
$msg = new MsgStack();
$spicPath="";
$lpicPath="";

//delete database info
if($_GET["delid"]!=""){
  $f = mysql_query("select * from gallery where id= ".$_GET["delid"]);

  if($f){
    while($res = mysql_fetch_array($f)){
      $spicPath = $res["smallPic"];
      $lpicPath = $res["largePic"];      
    }
    $delQuery = mysql_query("delete from gallery where id=".$_GET["delid"]);

    if($delQuery){
      $msg->push("delete from database successful!");
    }else{
      $msg->push("Cannot delete the picture info from database!");
      $msg->isErr = true;
      $_SESSION["GALLERY_DEL_ERROR"]=$msg->getMsg();  
   echo $msg->getMsg();

      Util::redirect("gallery.php","GALLERY_DEL_ERROR");
    }
  }
  else{
    $msg->push("Cannot find the delete picture");
    $_SESSION['GALLERY_DEL_ERROR'];
    $msg->isErr = true;
 
    Util::redirect("gallery.php","GALLERY_DEL_ERROR");
  }
  
}

//delete file 
$delSmallPic = Util::deleteFile($spicPath);
$delLargePic = Util::deleteFile($lpicPath);
if(!$delSmallPic){
  $msg->push("Warning:cannot delete the small piture of the item from the file system of remote server.");
}
if(!$delLargePic){
  $msg->push("Warning:cannot delete the large piture of the item from the file system of remote server.");  
}
$_SESSION["GALLERY_DEL_OK"]=$msg->getmsg();
Util::redirect("gallery.php","GALLERY_DEL_OK");

?>